namespace Xsxiaosa.Net
{
    using System;
    using System.Net;

    public class FtpException : InvalidOperationException
    {
        // Methods
        public FtpException() : this(Xsxiaosa.Net.Messages.GetString(typeof(FtpStrings), "UnclassifiableError"), null, FtpExceptionStatus.UnclassifiableError)
        {
        }

        internal FtpException(FtpException e) : base(e.Message, e.InnerException)
        {
            this._status = e.Status;
            this._response = e.Response;
            this._transfered = ((long) 0);
        }

        public FtpException(FtpResponse response) : base(string.Concat(objArray1))
        {
            object[] objArray1 = new object[4];
            char[] chArray1 = new char[2];
            chArray1[0] = ' ';
            chArray1[1] = '.';
            objArray1[0] = response.Description.Trim(chArray1);
            objArray1[1] = " (";
            objArray1[2] = response.Code;
            objArray1[3] = ").";
            if (response != null)
            {
                this._response = response;
                this._status = FtpExceptionStatus.ProtocolError;
                return;
            }
            this._status = FtpExceptionStatus.UnclassifiableError;
        }

        public FtpException(string message) : this(message, null, FtpExceptionStatus.UnclassifiableError)
        {
        }

        internal FtpException(FtpException e, long transfered) : base(e.Message, e.InnerException)
        {
            this._status = e.Status;
            this._response = e.Response;
            this._transfered = transfered;
        }

        public FtpException(string message, FtpExceptionStatus status) : this(message, null, status)
        {
        }

        public FtpException(string message, Exception innerException) : this(message, innerException, FtpExceptionStatus.UnclassifiableError)
        {
        }

        public FtpException(string message, Exception innerException, FtpExceptionStatus status) : base(message, innerException)
        {
            if (status == FtpExceptionStatus.ProtocolError)
            {
                this._status = FtpExceptionStatus.UnclassifiableError;
                return;
            }
            this._status = status;
        }

        internal WebException ToWebException()
        {
            WebExceptionStatus status1;
            FtpExceptionStatus status2 = this._status;
            switch (status2)
            {
                case FtpExceptionStatus.ConnectFailure:
                {
                    status1 = WebExceptionStatus.ConnectFailure;
                    goto Label_0071;
                }
                case FtpExceptionStatus.ConnectionClosed:
                {
                    status1 = WebExceptionStatus.ConnectionClosed;
                    goto Label_0071;
                }
                case FtpExceptionStatus.SocketError:
                case FtpExceptionStatus.UnclassifiableError:
                case FtpExceptionStatus.OperationAborted:
                {
                    goto Label_006F;
                }
                case FtpExceptionStatus.NameResolutionFailure:
                {
                    status1 = WebExceptionStatus.NameResolutionFailure;
                    goto Label_0071;
                }
                case FtpExceptionStatus.Pending:
                {
                    status1 = WebExceptionStatus.Pending;
                    goto Label_0071;
                }
                case FtpExceptionStatus.ProtocolError:
                {
                    status1 = WebExceptionStatus.ProtocolError;
                    goto Label_0071;
                }
                case FtpExceptionStatus.ProxyNameResolutionFailure:
                {
                    status1 = WebExceptionStatus.ProxyNameResolutionFailure;
                    goto Label_0071;
                }
                case FtpExceptionStatus.ReceiveFailure:
                {
                    status1 = WebExceptionStatus.ReceiveFailure;
                    goto Label_0071;
                }
                case FtpExceptionStatus.SendFailure:
                {
                    status1 = WebExceptionStatus.SendFailure;
                    goto Label_0071;
                }
                case FtpExceptionStatus.ServerProtocolViolation:
                {
                    status1 = WebExceptionStatus.ServerProtocolViolation;
                    goto Label_0071;
                }
                case FtpExceptionStatus.Timeout:
                {
                    status1 = WebExceptionStatus.Timeout;
                    goto Label_0071;
                }
            }
        Label_006F:
            status1 = WebExceptionStatus.RequestCanceled;
        Label_0071:
            if (this._status != FtpExceptionStatus.AsyncError)
            {
                return new WebException(this.Message, this, status1, null);
            }
            return new WebException(this.Message, base.InnerException, status1, null);
        }


        // Properties
        public FtpResponse Response
        {
            get
            {
                return this._response;
            }
        }

        public FtpExceptionStatus Status
        {
            get
            {
                return this._status;
            }
        }

        public long Transfered
        {
            get
            {
                return this._transfered;
            }
        }


        // Fields
        private FtpResponse _response;
        private FtpExceptionStatus _status;
        private long _transfered;
//jyj add
		private static object[] objArray1;

    }
}

